const express = require('express')
const app = express()
const db = require('./db/connect')
const path = require('path')
const bodyparser = require('body-parser')
const cors = require('cors')
const cookieParse = require('cookie-parser')
const session = require('express-session')
    // const jwt = require('./unitl/jwt')

// aession整体配置
app.use(session({
    secret: 'ssssssssss',
    cookie: { maxAge: 60 * 1000 * 3 },
    resave: true,
    saveUninitialized: false
}))


app.use(cors())
app.use(bodyparser.urlencoded({ extended: false }))
app.use(bodyparser.json())
    //路由
app.use('/public', express.static(path.join(__dirname, './static')))
console.log(path.join(__dirname, './image'));
const request = require('request')
const userRouter = require('./router/userRouter')
    // const foodRouter = require('./router/foodRouter')
    // const fileRouter = require('./router/fileRouter')



app.get('/cors', (req, res) => {
    request('https://api.bilibili.com/x/web-interface/zone?jsonp=jsonp', (err, response, body) => {
        if (!err) {
            res.send(body)
        }
    })
})
app.use('/user', userRouter)

session
// app.use('/food', (req, res, next) => {
//     // console.log(req.body)
//     if (req.session.login) {
//         console.log(req.session)
//         next()
//     } else {
//         res.send({ err: -999, msg: '请先登录' })
//     }

// }, foodRouter)


// //token
// app.use('/food', (req, res, next) => {
//     // console.log(req.body)
//     let { token } = req.body
//     jwt.checktoken(token)
//         .then((data) => {
//             next()
//         })
//         .catch((err) => {
//             res.send({ err: -99, msg: 'token非法' })
//         })

// }, foodRouter)


// app.use('/file', fileRouter)




app.listen('3000', () => {
    console.log('server start');
})